﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AiXiu.Web
{
    public partial class Land : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (Page.IsValid) {
                string userName = txtUserName.Text;
                string password = txtPassword.Text;
                IUserManager userManager = new UserManager();
                OperResult<TBUsers> operResult = userManager.LoginByUserName(userName, password);
                if (operResult.StatusCode == StatusCode.Succeed)
                {
                    //缓存用户资料
                    TBUsers tBUsers = operResult.ReadResult();
                    IdentityManager.SaveUser(tBUsers);
                    //脚本跳转（配合forms身份验证）
                    string redirectUrl = Request.QueryString["ReturnUrl"];
                    if (string.IsNullOrWhiteSpace(redirectUrl)) 
                    {
                        redirectUrl = "Personal.aspx";
                    }
                    this.Redirect("Ignsuccess",redirectUrl);
                }
                else {
                    this.Alert("lgnfail", operResult.Message ?? "操作失败!");
                }
            }
        }
    }
}